<template>
  <div class="">
    <el-dialog :title="title" :visible.sync="dialogBoole" width="500px">
      <el-form :model="form" ref="form" label-width="90px" class="demo-form-inline">
        <el-form-item label="类型" prop="contractName">
          <el-radio-group v-model="form.radio" v-if="isBool">
            <el-radio :label="1">个人开票</el-radio>
            <el-radio :label="2">企业开票</el-radio>
          </el-radio-group>
          <span v-else>
            <span v-if="form.radio === 1">个人开票</span>
            <span v-if="form.radio === 2">企业开票</span>
          </span>
        </el-form-item>
        <el-form-item label="开票金额" prop="invoiceAmount">
          <el-input v-model="form.invoiceAmount" disabled/>
        </el-form-item>
        <el-form-item label="发票类型:" prop="invoiceTypeStr" :rules="!isBool? []: rules.invoiceTypeStr">
          <el-select v-model="form.invoiceTypeStr" v-if="isBool" style="width: 100%" placeholder="请选择发票类型">
            <el-option v-for="item in dict.type.order_invoice_type" :key="item.value" :label="item.lable"
                       :value="item.value"/>
          </el-select>
          <span v-else></span>
        </el-form-item>
        <el-form-item label="客户名称:" prop="customerName" :rules="!isBool? []: rules.customerName">
          <el-input v-if="isBool" v-model="form.customerName" placeholder="请输入客户名称"/>
          <span v-else>{{ form.customerName }}</span>
        </el-form-item>
        <el-form-item label="开户银行:" prop="contractRemark">
          <el-input v-if="isBool" v-model="form.contractRemark" placeholder="请输入说明"/>
          <span v-else></span>
        </el-form-item>
        <el-form-item label="账户:" prop="customerBankAccount" :rules="!isBool? []: rules.customerBankAccount">
          <el-input v-if="isBool" v-model="form.customerBankAccount" placeholder="请输入账户"/>
          <span v-else>{{ form.customerBankAccount }}</span>
        </el-form-item>
        <el-form-item label="地址:" prop="customerAddr">
          <el-input v-if="isBool" v-model="form.customerAddr" placeholder="请输入说明"/>
          <span v-else>{{ form.customerAddr }}</span>
        </el-form-item>
        <el-form-item label="联系电话:" prop="contractRemark">
          <el-input v-if="isBool" v-model="form.contractRemark" placeholder="请输入说明"/>
          <span v-else></span>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="handleClear">取 消</el-button>
        <el-button type="primary" @click="handleSubmit">确 定</el-button>
      </div>

    </el-dialog>
  </div>
</template>

<script>
import {financeProceedsInvoice} from '@/api/vehicleDisposal/routineHandle.js'

export default {
  name: "invoice", //开票
  dicts: ["order_invoice_type"],
  computed: {
    required() {
      let a = this.title;
      return a;
    },
  },
  watch: {},
  data() {
    return {
      dialogBoole: false,
      form: {},
      title: "",
      isBool: false,
      rules: {
        invoiceTypeStr: [
          {required: true, message: "请选择发票类型", trigger: "change"},
        ],
        customerName: [
          {required: true, message: "请输入客户名称", trigger: "blur"},
        ],
        customerBankAccount: [
          {required: true, message: "请输入银行账户", trigger: "blur"},
        ],
      },
    };
  },
  created() {
  },
  mounted() {
  },
  methods: {
    handleOpen(type, row, bool) {
      this.title = type;
      this.isBool = bool;
      this.dialogBoole = true;
    },
    handleClear() {
      this.form = {}
      this.dialogBoole = false;
      this.$refs.form.resetField()
    },
    handleSubmit() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          financeProceedsInvoice(this.form).then(res => {
            if (res.code === 200) {
              this.$message.success('开票成功')
              this.$emit('reset')
              this.dialogBoole = false
            }
          })
        }
      });
      this.dialogBoole = false;
    },
  },
};
</script>

<style scoped lang=""></style>


